package com.fulihui.systemcore.dal.convertor;

import java.util.List;
import java.util.stream.Collectors;

import org.near.toolkit.common.DateUtils;
import org.springframework.beans.BeanUtils;

import com.fulihui.systemcore.dal.dataobj.VisitRecordDO;
import com.fulihui.systemcore.dto.VisitRecordDTO;

/**
 * 
 * @author leeson 2016年5月17日 下午1:43:19
 *
 */
public class VisitRecordConv {
    private static final String[] ignore = { "gmtCreate", "gmtModified" };

    public static VisitRecordDO convert2DO(VisitRecordDTO mo_) {
        if (mo_ == null) {
            return null;
        }

        VisitRecordDO do_ = new VisitRecordDO();
        BeanUtils.copyProperties(mo_, do_, ignore);

        do_.setGmtCreate(mo_.parseGmtCreate());
        do_.setGmtModified(mo_.parseGmtModified());

        return do_;
    }

    public static VisitRecordDTO convert2DTO(VisitRecordDO do_) {
        if (do_ == null) {
            return null;
        }

        VisitRecordDTO mo_ = new VisitRecordDTO();
        BeanUtils.copyProperties(do_, mo_, ignore);

        mo_.setGmtCreate(DateUtils.formatNewFormat(do_.getGmtCreate()));
        mo_.setGmtModified(DateUtils.formatNewFormat(do_.getGmtModified()));

        return mo_;
    }

    public static List<VisitRecordDTO> convert2List(List<VisitRecordDO> list) {
        return list.stream().map(VisitRecordConv::convert2DTO).collect(Collectors.toList());
    }
}